<template>
	<view class="p-l-20 p-r-20">
		<uv-search placeholder="请输入搜索内容" v-model="keyword" @search="searchFn"></uv-search>
		<view class="m-t-24">
			<block v-for="(item,i) in lists" :key="i">
				<shopItem :item="item" type="shop"></shopItem>
			</block>
		</view>
		<view class="bottom-mar"></view>

		<uv-load-more :status="loadStatus" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				keyword: '',
				city: '',
				lists: [],
				loadShow: true,
				loadStatus: 'loadmore',
				pageNum: 1
			};
		},
		onReachBottom() {
			// 触底加载
			this.getLists()
		},
		onShow() {
			uni.getStorage({
				key: 'city',
				success: res => {
					this.city = res.data
				},
				fail: err => {
					this.city = ''
				}
			})
		},

		methods: {
			searchFn() {
				this.lists = []
				this.loadShow = true,
				this.loadStatus = 'loadmore',
				this.pageNum = 1
				this.getLists()
			},
			getLists() {
				if (this.loadShow) {
					this.loadStatus = 'loading'
					this.loadShow = false
				this.$api.sendRequest({
					url: '/api/shop/lists',
					data: {
						page: this.pageNum,
						num: 10,
						search: this.keyword,
						district: '',
						city: this.city,
						businessarea_id: '',
						status: 'all',
						monthrent: 'all',
						area: 'all',
						type: 'all',
						transfer_fee: 'all',
						is_recommend: 1,
						is_deal: 0,
						min_area: '',
						max_area: '',
						min_month_rent: '',
						max_month_rent: '',
						min_transfer_fee: '',
						max_transfer_fee: '',
					},
					success: res => {
						this.lists.push(...res.data.data)
						if (res.data.data.length < 10) {
							this.loadShow = false
							this.loadStatus = 'nomore'
							return
						}
						this.pageNum++
						this.loadShow = true
						this.$forceUpdate()
					}
				})
			}
			},
		}
	}
</script>

<style lang="scss">

</style>
